/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hochschild.sgv.util;

import com.hochschild.sgv.domain.Usuario;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import java.io.File;
import java.io.IOException;

/**
 *
 * @author Christian Alexander Morales Vargas (cmorales.corporacion@gmail.com)
 */
public class SolicitudVacacion {
    private String ruta;

    public String getRuta() {
        return ruta;
    }

    public void setRuta(String ruta) {
        this.ruta = ruta;
    }
    
    
    public Document Solicitud(String ruta,Document document) throws IOException, DocumentException{
        this.ruta = ruta;
            document.open();
            document.addTitle("Sistema Gestión de Vacaciones");
            document.add(createTituloYEncabezado("MOVIMIENTO DE PERSONAL"));
            document.add(createTablaDatosGenerales());
            document.add(createTablaChecks());
            document.add(createTablaObservaciones());
            document.add(createTablaOpciones());
            document.add(createTablaPeriodos());
            document.add(createTablaFirmas());

            document.close();
        return document;
    }
    public PdfPTable createTituloYEncabezado(String titulo) throws IOException, DocumentException {
        PdfPTable table = new PdfPTable(4);
        table.setWidths(new int[]{2, 10, 1, 1});
        table.setWidthPercentage(100);
        PdfPCell cell;
        Font font = new Font(CreateFont(), 10, Font.BOLD, BaseColor.BLACK);

        //PRIMERA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", titulo), font));
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(4);
        cell.setFixedHeight(32f);
        table.addCell(cell);

        //SEGUNDA FILA
        cell = new PdfPCell(new Phrase(""));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(4);
        cell.setFixedHeight(10f);
        table.addCell(cell);

        //TERCERA FILA
        font = new Font(CreateFont(), 9, Font.BOLD, BaseColor.BLACK);
        String fechaActual= FechaUtil.fechaActual();
        cell = new PdfPCell(new Phrase(String.format("%s", "FECHA  : " + fechaActual), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(2);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "EMP."), font));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setFixedHeight(10f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setFixedHeight(10f);
        table.addCell(cell);

        //CUARTA FILA
        cell = new PdfPCell(new Phrase(""));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(4);
        cell.setFixedHeight(5f);
        table.addCell(cell);

        //QUINTA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "COMPAÑÍA  :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(2);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "OBR."), font));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setFixedHeight(10f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setFixedHeight(10f);
        table.addCell(cell);

        return table;
    }

    public PdfPTable createTablaDatosGenerales() throws IOException, DocumentException {
        PdfPTable table1 = new PdfPTable(1);
        table1.setWidths(new int[]{10});
        table1.setWidthPercentage(100);

        PdfPTable table = new PdfPTable(4);
        table.setWidths(new int[]{2, 7, 2, 3});
        table.setWidthPercentage(100);
        PdfPCell cell;
        Font font = new Font(CreateFont(), 9, Font.BOLD, BaseColor.BLACK);

        cell = new PdfPCell(new Phrase(""));
        cell.setBorder(PdfPCell.NO_BORDER);        
        cell.setFixedHeight(10f);
        table1.addCell(cell);
        
        //PRIMERA FILA 
        cell = new PdfPCell(new Phrase(String.format("%s", "NOMBRE :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        cell.setColspan(2);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "REGISTRO :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        cell.setColspan(2);
        table.addCell(cell);
        table1.addCell(table);

         //SEGUNDA FILA
        table = new PdfPTable(4);
        table.setWidths(new int[]{2, 7, 2, 3});
        table.setWidthPercentage(100);
        
        cell = new PdfPCell(new Phrase(String.format("%s", "UNIDAD OPERATIVA :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        cell.setColspan(2);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "ÁREA :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        cell.setColspan(2);
        table.addCell(cell);
        table1.addCell(table);
        
        return table1;
    }

    public PdfPTable createTablaChecks() throws IOException, DocumentException {
        PdfPTable table = new PdfPTable(10);
        table.setWidths(new float[]{0.8f, 0.4f, 0.8f, 0.4f, 1f, 0.4f, 1.3f, 0.4f, 1.4f, 0.4f});
        table.setWidthPercentage(100);
        PdfPCell cell;
        Font font = new Font(CreateFont(), 9, Font.BOLD, BaseColor.BLACK);

        cell = new PdfPCell(new Phrase(""));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(10);
        cell.setFixedHeight(10f);
        table.addCell(cell);

        //PRIMERA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "INGRESO :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);     
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "SALIDA :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "AUMENTO :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "CAMBIO TÍTULO :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "TRANSFERENCIA :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        table.addCell(cell);

        return table;
    }

    public PdfPTable createTablaObservaciones() throws IOException, DocumentException {
        PdfPTable tablePrincipal = new PdfPTable(1);
        tablePrincipal.setWidths(new int[]{10});
        tablePrincipal.setWidthPercentage(100);
        
        PdfPCell cell;

        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        //cell.setBorderWidth(2f);
        cell.setFixedHeight(10f);
        tablePrincipal.addCell(cell);

        String fs = File.separator;
         
        
        PdfPTable table = new PdfPTable(4);
        table.setWidths(new int[]{3, 6, 3, 6});
        table.setWidthPercentage(100);
        Font font = new Font(CreateFont(), 9, Font.BOLD, BaseColor.BLACK);

        //PRIMERA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "A PARTIR DEL :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(4);
        cell.setFixedHeight(20f);
        table.addCell(cell);

        //SEGUNDA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "TÍTULO ACTUAL"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        table.addCell(cell);

        Image foto = Image.getInstance(ruta + "images" + fs + "linea.gif");
        foto.scalePercent(40.0f);
        foto.setAlignment(Image.ALIGN_LEFT);
        cell = new PdfPCell();
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.addElement(foto);
        cell.setFixedHeight(20f);
        cell.setRowspan(4);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "TÍTULO NUEVO"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.addElement(foto);
        cell.setFixedHeight(20f);
        cell.setRowspan(4);
        table.addCell(cell);
        
        //TERCERA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "REMUNERACIÓN ACTUAL"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(30f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "REMUNERACIÓN NUEVA "), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(30f);
        table.addCell(cell);

        //CUARTA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "DPTO./SECC. ACTUAL"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(30f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "DPTO./SECC. NUEVO "), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(30f);
        table.addCell(cell);

        //QUINTA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "CE.CO. ACTUAL"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "CE.CO. NUEVO "), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        table.addCell(cell);

        //SEXTA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "CONTRATADO/EVENTUAL HASTA :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setColspan(4);
        cell.setFixedHeight(20f);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell();
        cell.addElement(table);
        cell.setBorderWidth(2f);
        tablePrincipal.addCell(cell);

        font = new Font(CreateFont(), 9, Font.UNDERLINE|Font.BOLD, BaseColor.BLACK);
        //cell.setBorder(PdfPCell.NO_BORDER);        
        cell = new PdfPCell(new Phrase(String.format("%s", "OBSERVACIONES :"), font));
        cell.setFixedHeight(40f);
        cell.setBorderWidth(2f);
        tablePrincipal.addCell(cell);

        return tablePrincipal;
    }

    public PdfPTable createTablaOpciones() throws IOException, DocumentException {
        PdfPTable table = new PdfPTable(11);
        table.setWidths(new float[]{0.3f, 1f, 0.4f, 0.3f, 1f, 0.4f, 0.3f, 1f, 0.4f, 0.3f, 1f});
        table.setWidthPercentage(100);
        PdfPCell cell;
        Font font = new Font(CreateFont(), 9, Font.BOLD, BaseColor.BLACK);
        Font font1 = new Font(CreateFont(), 11, Font.BOLD, BaseColor.BLACK);

        cell = new PdfPCell(new Phrase(""));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(11);
        cell.setFixedHeight(20f);
        table.addCell(cell);

        //PRIMERA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "X"), font1));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setUseAscender(true);
        cell.setFixedHeight(20f);
        cell.setBorderWidth(1f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "VACACIONES"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setUseAscender(true);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setFixedHeight(20f);
        cell.setBorderWidth(1f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "PERMISO"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setUseAscender(true);
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);
        
        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setFixedHeight(20f);
        cell.setBorderWidth(1f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "DESCANSO MÉDICO"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setUseAscender(true);
        //cell.setFixedHeight(20f);
        //cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setFixedHeight(20f);
        cell.setBorderWidth(1f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "ACCIDENTE"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setUseAscender(true);
        table.addCell(cell);

        //SEGUNDA FILA
        cell = new PdfPCell(new Phrase(""));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(11);
        cell.setFixedHeight(8f);
        table.addCell(cell);

        //TERCERA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setFixedHeight(20f);
        cell.setBorderWidth(1f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "SUSPENSIÓN"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setUseAscender(true);
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setFixedHeight(20f);
        cell.setBorderWidth(1f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "AUSENCIA INJUSTIFICADA"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setUseAscender(true);
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setFixedHeight(20f);
        cell.setBorderWidth(1f);
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setFixedHeight(20f);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);
        
        return table;
    }

    public PdfPTable createTablaPeriodos() throws IOException, DocumentException {
        PdfPTable tablePrincipal = new PdfPTable(1);
        tablePrincipal.setWidths(new int[]{10});
        tablePrincipal.setWidthPercentage(100);

        PdfPCell cell;

        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        //cell.setBorderWidth(2f);
        cell.setFixedHeight(20f);
        tablePrincipal.addCell(cell);

        PdfPTable table = new PdfPTable(6);
        table.setWidths(new int[]{3, 6, 1, 3, 6, 1});
        table.setWidthPercentage(100);
        Font font = new Font(CreateFont(), 9, Font.BOLD, BaseColor.BLACK);

        //PRIMERA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "FECHA DE INGRESO :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(6);
        cell.setFixedHeight(20f);
        table.addCell(cell);

        //SEGUNDA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "DESDE EL :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        //cell.setColspan(2);
        cell.setFixedHeight(15f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBackgroundColor(new BaseColor(225, 225, 225));
        cell.setBorder(PdfPCell.NO_BORDER);
        //cell.setColspan(2);
        //cell.setFixedHeight(10f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        //cell.setColspan(2);
        //cell.setFixedHeight(10f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "HASTA EL :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        //cell.setColspan(2);
        //cell.setFixedHeight(20f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBackgroundColor(new BaseColor(225, 225, 225));
        cell.setBorder(PdfPCell.NO_BORDER);
        //cell.setColspan(2);
        //cell.setFixedHeight(20f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        //cell.setColspan(2);
        //cell.setFixedHeight(20f);
        table.addCell(cell);


        //TERCERA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(6);
        cell.setFixedHeight(5f);
        table.addCell(cell);

        //CUARTA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "PERIODO DEL :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(2);
        cell.setFixedHeight(20f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        //cell.setColspan(2);
        //cell.setFixedHeight(10f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "AL :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(3);
        cell.setFixedHeight(20f);
        table.addCell(cell);

        //QUINTA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "N° DÍAS :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        //cell.setColspan(5);
        //cell.setFixedHeight(20f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBackgroundColor(new BaseColor(225, 225, 225));
        cell.setBorder(PdfPCell.NO_BORDER);
        //cell.setColspan(2);
        //cell.setFixedHeight(10f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(4);
        //cell.setFixedHeight(20f);
        table.addCell(cell);

        //SEXTA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(6);
        cell.setFixedHeight(5f);
        table.addCell(cell);

        //SEPTIMA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "CON GOCE DE HABER :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(2);
        cell.setFixedHeight(20f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        //cell.setColspan(2);
        //cell.setFixedHeight(10f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "SIN GOCE DE HABER :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(3);
        cell.setFixedHeight(20f);
        table.addCell(cell);

        //OCTAVA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "MOTIVO U OBSERVACIONES :"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(6);
        cell.setFixedHeight(20f);
        table.addCell(cell);

        tablePrincipal.addCell(table);

        return tablePrincipal;
    }

    public PdfPTable createTablaFirmas() throws IOException, DocumentException {
        PdfPCell cell;

        PdfPTable table = new PdfPTable(2);
        table.setWidths(new int[]{1, 1});
        table.setWidthPercentage(100);
        Font font = new Font(CreateFont(), 9, Font.BOLD, BaseColor.BLACK);

        //PRIMERA FILA
        cell = new PdfPCell();        
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(50f);
        cell.setColspan(2);
        table.addCell(cell);

        //SEGUNDA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "_______________________________"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER); 
        table.addCell(cell);

        table.addCell(cell);

        //TERCERA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "FIRMA DEL TRABAJADOR"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "AUTORIZADO JEFE DE DPTO."), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        table.addCell(cell);

        //CUARTA FILA
        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(50f);
        cell.setColspan(2);
        table.addCell(cell);

        //QUINTA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "_______________________________"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);

        table.addCell(cell);

        //SEXTA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "APROBADO RR. HH."), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "APROBADO GERENCIA"), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        table.addCell(cell);

        return table;
    }

    public BaseFont CreateFont() {
        BaseFont arial = null;
        String fs = File.separator;
        try {
            arial = BaseFont.createFont(ruta + "fuente" + fs + "arial.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return arial;
    }
    
    //DVQ 19122012
    public Document Solicitud(String ruta,Document document, Usuario usuario) throws IOException, DocumentException{
        this.ruta = ruta;
            document.open();
            document.addTitle("Sistema Gestión de Vacaciones");
            document.add(createTituloYEncabezado("MOVIMIENTO DE PERSONAL", usuario));
            document.add(createTablaDatosGenerales(usuario));
            document.add(createTablaChecks());
            document.add(createTablaObservaciones());
            document.add(createTablaOpciones());
            document.add(createTablaPeriodos());
            document.add(createTablaFirmas());

            document.close();
        return document;
    }

    public PdfPTable createTablaDatosGenerales(Usuario usuario) throws IOException, DocumentException {
        PdfPTable table1 = new PdfPTable(1);
        table1.setWidths(new int[]{10});
        table1.setWidthPercentage(100);

        PdfPTable table = new PdfPTable(4);
        table.setWidths(new int[]{2, 7, 2, 3});
        table.setWidthPercentage(100);
        PdfPCell cell;
        Font font = new Font(CreateFont(), 9, Font.BOLD, BaseColor.BLACK);

        cell = new PdfPCell(new Phrase(""));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(10f);
        table1.addCell(cell);

        //PRIMERA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "NOMBRE :  " + usuario.getNombreUsuario()), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        cell.setColspan(2);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "REGISTRO :  " + usuario.getIdPersonal()), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        cell.setColspan(2);
        table.addCell(cell);
        table1.addCell(table);

         //SEGUNDA FILA
        table = new PdfPTable(4);
        table.setWidths(new int[]{2, 7, 2, 3});
        table.setWidthPercentage(100);

        cell = new PdfPCell(new Phrase(String.format("%s", "UNIDAD OPERATIVA :  " + usuario.getDivisionUsuario()), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        cell.setColspan(2);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "ÁREA :  " + usuario.getAreaUsuario()), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setFixedHeight(20f);
        cell.setColspan(2);
        table.addCell(cell);
        table1.addCell(table);

        return table1;
    }

    public PdfPTable createTituloYEncabezado(String titulo, Usuario usuario) throws IOException, DocumentException {
        PdfPTable table = new PdfPTable(4);
        table.setWidths(new int[]{2, 10, 1, 1});
        table.setWidthPercentage(100);
        PdfPCell cell;
        Font font = new Font(CreateFont(), 10, Font.BOLD, BaseColor.BLACK);

        //PRIMERA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", titulo), font));
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(4);
        cell.setFixedHeight(32f);
        table.addCell(cell);

        //SEGUNDA FILA
        cell = new PdfPCell(new Phrase(""));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(4);
        cell.setFixedHeight(10f);
        table.addCell(cell);

        //TERCERA FILA
        font = new Font(CreateFont(), 9, Font.BOLD, BaseColor.BLACK);
        String fechaActual= FechaUtil.fechaActual();
        cell = new PdfPCell(new Phrase(String.format("%s", "FECHA  : " + fechaActual), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(2);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "EMP."), font));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setFixedHeight(10f);
        table.addCell(cell);

        if(usuario.getIdGrupoPersonal().equals("E")){
            cell = new PdfPCell(new Phrase(String.format("%s", "X"), font));
        }
        else{
            cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        }
        
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setFixedHeight(10f);
        table.addCell(cell);

        //CUARTA FILA
        cell = new PdfPCell(new Phrase(""));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(4);
        cell.setFixedHeight(5f);
        table.addCell(cell);

        //QUINTA FILA
        cell = new PdfPCell(new Phrase(String.format("%s", "COMPAÑÍA  :  " + usuario.getSociedadUsuario()), font));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setColspan(2);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.format("%s", "OBR."), font));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setFixedHeight(10f);
        table.addCell(cell);

        if(usuario.getIdGrupoPersonal().equals("O")){
            cell = new PdfPCell(new Phrase(String.format("%s", "X"), font));
        }
        else{
            cell = new PdfPCell(new Phrase(String.format("%s", ""), font));
        }
        
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setFixedHeight(10f);
        table.addCell(cell);

        return table;
    }
}
